﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using LiveWebServiceBase;

namespace LiveWebService
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {
            Settings.Logging.LogItem liItem = new Settings.Logging.LogItem();

            liItem.ServiceUserName = System.Web.HttpContext.Current.User.Identity.Name;


            liItem.LiveID = "None";
            liItem.Arguments = new List<string>();

            Exception exLast = System.Web.HttpContext.Current.AllErrors.LastOrDefault();
            liItem.IsSuccessed = false;

            if (exLast != null)
            {
                liItem.ExceptionMessage = exLast.Message;
                liItem.ExceptionSource = exLast.StackTrace;
            }

            liItem.LogEntryType = System.Diagnostics.EventLogEntryType.Error;

            liItem.WriteLogRecord();
        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}